INCLUDE(xcmake_env)

##                                                                                                     
# @brief: 收集文件                                                                                     
# @param dir: 目录                                                                                     
# @param glob_exp: 通配规则                                                                            
# @param recursion: 是否递归                                                                           
# @param {name} result:    返回数据（文件列表）                                                        
##                                                                                                     
function(XCollectFiles arg)                                                                            
    #MESSAGE(STATUS "XCollectFiles: ARGN:" ${ARGN})                                                    
    #MESSAGE(STATUS "XCollectFiles: ARGC:" ${ARGC})                                                    
    #MESSAGE(STATUS "XCollectFiles: ARGV:" ${ARGV})                                                    
                                                                                                       
    #LIST(LENGTH ARGV argv_len)                                                                        
    #MESSAGE(STATUS "length of ARGV: " ${argv_len})                                                    
    #SET(n 0)                                                                                          
    #WHILE(n LESS ${argv_len})                                                                         
        #LIST(GET ARGV ${n} argv_value)                                                                
        #MESSAGE(STATUS "param_" ${n} "=" ${argv_value})                                               
        #MATH(EXPR n "${n} + 1")                                                                       
    #ENDWHILE()                                                                                        
                                                                                                       
    SET(dir "")                                                                                        
    SET(glob_exp "")                                                                                   
    SET(resursion 0)                                                                                   
    LIST(GET ARGV 0 dir)                                                                               
    LIST(GET ARGV 1 glob_exp)                                                                          
    LIST(GET ARGV 2 resursion)                                                                         
    LIST(GET ARGV 3 result)                                                                            
    #MESSAGE(STATUS "call XCollectFiles:" ${dir} "," ${glob_exp} "," ${resursion} "," ${result})       
    SET(tem_files "")                                                                                  
    IF(${resursion})                                                                                   
        FILE(GLOB_RECURSE tem_files ${dir} ${glob_exp})                                                
        #MESSAGE(STATUS "GLOB_RECURSE; " ${dir} ${glob_exp})                                           
        #MESSAGE(STATUS "===:" ${tem_files})                                                           
    ELSE()                                                                                             
        FILE(GLOB tem_files ${dir} ${glob_exp})                                                        
    ENDIF()                                                                                            
    SET(${result} ${tem_files} PARENT_SCOPE)                                                           
endfunction()                                                                                          


##                                                                                                                
# @brief: 收集c和cpp源码文件                                                                                      
# @param dir: 目录                                                                                                
# @param resursion: 是否递归                                                                                      
# @param result: 结果集                                                                                           
##                                                                                                                
function(XCollectCAndCppSourceCodeFiles arg)                                                                      
    #参数设置                                                                                                     
    LIST(GET ARGV 0 dir)                                                                                          
    LIST(GET ARGV 1 resursion)                                                                                    
    LIST(GET ARGV 2 result)                                                                                       
                                                                                                                  
    XCollectFiles(${dir} "*.h"   ${resursion} h_files)                                                            
    XCollectFiles(${dir} "*.c"   ${resursion} c_files)                                                            
    XCollectFiles(${dir} "*.hh"  ${resursion} hh_files)                                                           
    XCollectFiles(${dir} "*.cc"  ${resursion} cc_files)                                                           
    XCollectFiles(${dir} "*.hpp" ${resursion} hpp_files)                                                          
    XCollectFiles(${dir} "*.cpp" ${resursion} cpp_files)                                                          
    XCollectFiles(${dir} "*.inc" ${resursion} inc_files)                                                          
    FILE(GLOB_RECURSE tem ${dir} "*.*")                                                                           
    #MESSAGE(STATUS ${tem})                                                                                       
    #MESSAGE(STATUS "param:" ${dir} "|" ${resursion} "|" ${result})                                               
    #MESSAGE(STATUS "H:" ${h_files})                                                                              
    #MESSAGE(STATUS "CC:" ${cc_files})                                                                            
    #MESSAGE(STATUS "ALL:" ${h_files} ${c_files} ${hh_files} ${cc_files} ${hpp_files} ${cpp_files} ${inc_files} ) 
                                                                                                                  
    SET(${result}                                                                                                 
        ${h_files} ${c_files} ${hh_files} ${cc_files} ${hpp_files} ${cpp_files} ${inc_files}                      
        PARENT_SCOPE)                                                                                             
endfunction()                                                                                                     
